﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Styx;
using Styx.Combat.CombatRoutine;
using Styx.Helpers;
using Styx.Logic;
using Styx.Logic.BehaviorTree;
using Styx.Logic.Combat;
using Styx.Logic.Pathing;
using Styx.Logic.POI;
using Styx.WoWInternals.WoWObjects;
using TreeSharp;
using Action = TreeSharp.Action;
using Sequence = TreeSharp.Sequence;
using Styx.WoWInternals;


namespace Healz.Druid.Spells
{
    class MarkoftheWild
    {
        public const string SpellName = "Mark of the Wild";

        public static bool Pulse()
        {
            // Really not thinking atm, will fix this later
            if (ObjectManager.Me.IsInInstance || Battlegrounds.IsInsideBattleground) { } else { return false; }
            if (!SpellManager.Spells[SpellName].CanCast) return false;
            if (PeopleWithoutMOTW == 0) return false;

            // Cast and Write
            Utils.WriteCast(SpellName);
            SpellManager.Cast(SpellName, StyxWoW.Me);
            StyxWoW.SleepForLagDuration();

            return true;
        }


        // Gets people under our flag to trigger Tree of life
        public static int PeopleWithoutMOTW
        {
            get
            {
                return (int)(from Unit in ObjectManager.GetObjectsOfType<WoWPlayer>(true, true)
                             where !Unit.Dead
                             where Unit.Distance2D < 30
                             where Unit.CurrentHealth > 1
                             where !Unit.HasAura(SpellName)
                             where Unit.IsFriendly
                             select Unit).Count();
            }
        }
    }
}
